import fs from 'fs'
import path from 'path'

export function scanApiFiles(dir: string, relativePath = '', apiFiles: string[] = []) {
  const entries = fs.readdirSync(dir, { withFileTypes: true });
  entries.forEach((entry) => {
    if (entry.isDirectory()) {
      const subPath = path.posix.join(relativePath, entry.name);
      scanApiFiles(path.join(dir, entry.name), subPath, apiFiles);
    } else if (entry.isFile()) {
      const fullPath = path.posix.join(relativePath, entry.name);
      apiFiles.push(fullPath);
    }
  });
  return apiFiles;
}